package org.algorithm.二师兄.数组.三月.第三周;

/**
 * @date 2022/03/17 10:08 PM
 * @description:  周五作业
 *
 *
 * url: https://leetcode-cn.com/problems/container-with-most-water/
 */
public class 盛最多水的容器 {

    public static void main(String[] args) {
        int[] nums = {1,8,6,2,5,4,8,3,7};
        System.out.println(maxArea(nums));
    }


    public static int maxArea(int[] nums){
        if(nums == null || nums.length<2){
            return 0;
        }
        int left = 0;
        int right = nums.length-1;
        int ans = 0;
        while (left<right){
            //最小边
            int lr =  Math.min(nums[left],nums[right]);
            ans = Math.max(ans,lr*(right-left));
            if(nums[left]<nums[right]){
                left++;
            }else {
                right--;
            }
        }
        return ans;
    }


}
